import request from '@/utils/request'
import qs from 'qs'
const BASIC_URL = import.meta.env.VITE_API_PATH
async function GET(url, data, options) {
  return request(BASIC_URL + url, {
    params: data,
    method: 'GET',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    options
  })
}
// POST默认是form表单形式
function POST(url, data, options) {
  if (options && options.dataType === 'json') {
    return request({
      url: BASIC_URL + url,
      method: 'POST',
      headers: {
        'Content-Type': 'application/json'
      },
      data: data,
      options
    })
  } else {
    return request({
      url: BASIC_URL + url,
      method: 'POST',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      data: qs.stringify(data),
      options
    })
  }
}
function DELETE(url, data, options) {
  return request({
    url: BASIC_URL + url,
    method: 'DELETE',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    data: qs.stringify(data),
    options
  })
}
// POST默认是json形式
function PUT(url, data, options) {
  if (options && options.dataType === 'form') {
    return request({
      url: BASIC_URL + url,
      method: 'PUT',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      data: qs.stringify(data),
      options
    })
  } else {
    return request({
      url: BASIC_URL + url,
      method: 'PUT',
      data: data,
      options
    })
  }
}

export { PUT, DELETE, POST, GET }
